package com.bear.fastrepair.mvvm.data

import com.bear.fastrepair.http.api.employee.EmployeeService2
import com.bear.fastrepair.http.client.RetrofitManager
import com.bear.fastrepair.mvvm.data.login.LoggedInType
import com.bear.fastrepair.utils.*

class MainDataSource {
    suspend fun loginStatus(): LoggedInType {
        val logged = SharedPreferencesHelper.getString(ACCOUNT_KEY)?.isNotEmpty() == true
        val type = SharedPreferencesHelper.getInt(ACCOUNT_TYPE_KEY) ?: -1
        return LoggedInType(logged, type)
    }

    suspend fun getEmployeePersonalInfo() = try {
        val token = SharedPreferencesHelper.getString(ACCOUNT_TOKEN_KEY) ?: ""
        RetrofitManager.getServiceSetToken(URL_MOBILE, EmployeeService2::class.java, token)
            .getPersonalInfo().let {
                if (it.code == 0) Result.Success(it) else Result.Error(data = it)
            }
    } catch (e: Exception) {
        Result.Error(e)
    }
}